package com.cskaoyan.shopping.converter;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContent;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.dto.PanelContentItemDto;
import com.cskaoyan.shopping.dto.PanelDto;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


/**
 * @author lizhenhao
 * @ClassName PanelConverterImpl.java
 * @Description TODO
 * @createTime 2022年06月17日 16:42:00
 */

@Component
public class PanelConverterImpl implements PanelConverter{
    @Override
    public PanelDto panel2Dto(Panel panel) {

        if (panel == null){
            return null;
        }

        PanelDto panelDto = new PanelDto();

        BeanUtils.copyProperties(panel,panelDto);

        return panelDto;
    }

    @Override
    public List<PanelDto> panels2Dto(List<Panel> panels) {
        if ( panels == null ) {
            return null;
        }

        List<PanelDto> list = new ArrayList<>( panels.size() );
        for ( Panel panel : panels ) {
            list.add( panel2Dto( panel ) );
        }

        return list;
    }

    @Override
    public PanelContentItemDto panelContentItem2Dto(PanelContentItem panelContentItem) {
        if (panelContentItem == null){
            return null;
        }

        PanelContentItemDto panelContentItemDto = new PanelContentItemDto();

        BeanUtils.copyProperties(panelContentItem,panelContentItemDto);

        return panelContentItemDto;
    }

    @Override
    public List<PanelContentItemDto> panelContentItems2Dto(List<PanelContentItem> panelContentItems) {
        if ( panelContentItems == null ) {
            return null;
        }

        List<PanelContentItemDto> list = new ArrayList<>( panelContentItems.size() );
        for ( PanelContentItem panel : panelContentItems ) {
            list.add( panelContentItem2Dto( panel ) );
        }

        return list;
    }

    @Override
    public PanelContentDto panelContent2Dto(PanelContent panelContent) {
        if (panelContent == null){
            return null;
        }

        PanelContentDto panelContentDto = new PanelContentDto();

        BeanUtils.copyProperties(panelContent,panelContentDto);

        return panelContentDto;
    }

    @Override
    public List<PanelContentDto> panelContents2Dto(List<PanelContent> panelContents) {
        if ( panelContents == null ) {
            return null;
        }

        List<PanelContentDto> list = new ArrayList<>( panelContents.size() );
        for ( PanelContent panelContent : panelContents ) {
            list.add( panelContent2Dto( panelContent ) );
        }

        return list;
    }
}
